package com.mycalendar;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
//import android.util.Log;
import android.view.View;

/**
 * ViewPager wrapContent解决方案
 */
public class MyViewPager extends ViewPager {

	private int linesCount = 6;

	/**
	 * Constructor
	 * 
	 * @param context
	 *            the context
	 */
	public MyViewPager(Context context) {
		super(context);
	}

	/**
	 * Constructor
	 * 
	 * @param context
	 *            the context
	 * @param attrs
	 *            the attribute set
	 */
	public MyViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

		int height = 0;
		for (int i = 0; i < getChildCount(); i++) {
			View child = getChildAt(i);
			child.measure(widthMeasureSpec,
					MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
			int h = child.getMeasuredHeight();
			if (h > height) {
				height = h;
			}
		}

		height = height * linesCount + 5;
		heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
				MeasureSpec.EXACTLY);

		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		
	}

	public int getLinesCount() {
		return linesCount;
	}

	public void setLinesCount(int linesCount) {
		this.linesCount = linesCount;
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent arg0) {
		//return super.onInterceptTouchEvent(arg0);
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent arg0) {
		//return super.onTouchEvent(arg0);
		return false;
	}

}
